package com.hz.ruoyiequipment.data.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hz.ruoyiequipment.data.domain.AgrEquipmentCq;
import com.hz.ruoyiequipment.data.domain.vo.CqEquipment;
import com.hz.ruoyiequipment.data.domain.vo.CqTimeData;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @Author: xqd
 * @CreateDate: 2025/03/09/16:25
 * @Description: 虫情设备接口
 */
public interface AgrEquipmentCqMapper extends BaseMapper<CqEquipment> {

    /**
     * @param agrEquipmentCq 虫情设备实体类
     * @return:
     * @Author: xqd
     * @Date: 2025/3/9 16:30
     * @Description: 新增虫情设备到设备表
     */
    @Insert("INSERT INTO agr_equipment_cq (equipment_id, cq_light_wave, cq_camera, cq_sensor, cq_update, cq_capacity) " +
            "value (#{equipmentId}, #{cqLightWave}, #{cqCamera}, #{cqSensor}, #{cqUpdate}, #{cqCapacity})")
    Integer insertAgrEquipmentCq(AgrEquipmentCq agrEquipmentCq);

    /**
     * @return:
     * @Author: xqd
     * @Date: 2025/3/9 16:31
     * @Description: 查看设备是否绑定地块
     */
    @Select("SELECT equipment_id FROM agr_equipment_plots WHERE equipment_id = #{equipmentId}")
    Integer getEquipmentId(Long equipmentId);

    /**
     * @return:
     * @Author: xqd
     * @Date: 2025/3/9 16:35
     * @Description: 修改虫情设备表中的数据
     */
    @Update("UPDATE agr_equipment_cq SET cq_light_wave = #{cqLightWave} " +
            "WHERE equipment_id = #{equipmentId}")
    Integer updateAgrEquipmentCq(CqEquipment cqEquipment);

    /**
     * @return:
     * @Author: xqd
     * @Date: 2025/3/9 16:40
     * @Description: 修改设备地块表中的数据
     */
    @Update("UPDATE agr_equipment_plots SET plots_id = #{plotsId} WHERE equipment_id = #{equipmentId}")
    Integer updateAgrEquipmentPlot(CqEquipment cqEquipment);

    /**
     * @return:
     * @Author: xqd
     * @Date: 2025/3/9 16:40
     * @Description: 将设备绑定的地块信息插入到设备地块表中
     */
    @Insert("INSERT INTO agr_equipment_plots (equipment_id, plots_id) " +
            "VALUE (#{equipmentId}, #{plotsId})")
    Integer insertAgrEquipmentPlot(CqEquipment cqEquipment);

    /**
     * @return:
     * @Author: xqd
     * @Date: 2025/3/9 16:41
     * @Description: 删除虫情设备表中的数据
     */
    @Delete("DELETE FROM agr_equipment_cq WHERE equipment_id = #{equipmentId}")
    Integer delAgrEquipmentCqByEquipmentId(Long equipmentId);

    /**
     * @return:
     * @Author: xqd
     * @Date: 2025/3/9 16:42
     * @Description: 删除设备地块表中的数据
     */
    @Delete("DELETE FROM agr_equipment_plots WHERE equipment_id = #{equipmentId}")
    Integer delAgrEquipmentPlotByEquipmentId(Long equipmentId);


    //查询虫情设备表中的数据
    CqTimeData getCqTimeData(Long equipmentId);

    //查询虫情设备表中的数据,历史数据
    List<CqTimeData> getCqTimeDatas(Long equipmentId);


    //查询虫情设备头部
    CqEquipment getCqTimeDataHead(Long equipmentId);


    //新增虫情历史数据信息

    // 新增的插入语句
    @Insert("INSERT INTO agr_pest_data " +
            "(equipment_id, pest_img, record_date, pest_one, pest_two, pest_three, pest_four,create_time) " +
            "VALUES (#{equipmentId}, #{pestImg}, #{recordDate}, #{pestOne}, #{pestTwo}, #{pestThree}, #{pestFour},#{createTime})")
    int insertCqTimeData(CqTimeData cqTimeData);
}
